/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel.panels.subpanels;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import planspiel.panels.GameScreen;
import admintool.imp03_data.IMP03_Message;
import admintool.imp03_data.IMP03_Platform;
/**
 *
 * @author Administrator
 */
public class GameContentMessage extends JPanel{
  
	private static final long serialVersionUID = 137801405039256213L;
	private GameScreen gameScreen = null;
    private IMP03_Message selectedMessage = null;
    private Image image = null;
    
    /**
     * 
     * @param gameScreen
     */
    public GameContentMessage(GameScreen gameScreen) {
        this.gameScreen = gameScreen;
        initDisplay();
        
        //Set Background Image
        try {
        	IMP03_Platform platform = this.gameScreen.getGame().getCurrentGameRoundController().getSelectedPlatform();
        	String imageName = "BackgroundMessage.png";
//        	if (platform.getPlatformName().toLowerCase().startsWith("facebook")) {
//        		imageName = "backgroundFacebook.jpg";
//        	} else if (platform.getPlatformName().toLowerCase().startsWith("stepstone")) {
//        		imageName = "backgroundStepstone.jpg";
//        	}
//        	if (platform.getPlatformName().toLowerCase().startsWith("twitter")) {
//        		imageName = "backgroundTwitter.jpg";
//        	}
//        	if (platform.getPlatformName().toLowerCase().startsWith("xing")) {
//        		imageName = "backgroundXing.jpg";
//        	}
            BufferedImage tmpImage = new BufferedImage(1000, 800, BufferedImage.TYPE_INT_RGB);
            tmpImage = ImageIO.read(this.getClass().getResourceAsStream("/planspiel/resources/" + imageName));
            this.image =  new ImageIcon(tmpImage.getScaledInstance(720, 580, Image.SCALE_SMOOTH)).getImage();
        } catch (Exception e) {
            e.printStackTrace();
        }         
    }

    /**
     * 
     * @return
     */
    public IMP03_Message getSelectedMessage() {
        return selectedMessage;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, null);
    }
    
    private void initDisplay(){
        
        // Auswahl linnks
        final JList cbMessage = new JList(IMP03_Message.getAllAvailableMessagesFromDB(true).toArray());
        cbMessage.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        cbMessage.setBounds(5, 180, 200, 400);
        
        final JLabel label1 = new JLabel("Betreff: ");
        final JLabel label2 = new JLabel("Inhalt: ");
        final JTextField text1 = new JTextField();
        text1.setEditable(false);
        final JTextArea text2 = new JTextArea();
        text2.setEditable(false);
        text2.setWrapStyleWord(true);
        text2.setLineWrap(true);
        
        this.setLayout(null);
        label1.setBounds(270, 100, 400, 20);
        text1.setBounds(270, 130, 400, 25);
        label2.setBounds(270, 200, 400, 20);
        text2.setBounds(270, 230, 400, 250);
        
        this.add(cbMessage);
        this.add(label1);
        this.add(label2);
        this.add(text1);
        this.add(text2);
        
        this.validate();
        
        cbMessage.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
                selectedMessage = (IMP03_Message)(cbMessage.getSelectedValue());
                

                text1.setText(selectedMessage.getMessageSubject());
                text2.setText(selectedMessage.getMessageContent());
				
			}
       
        });
        
    }
}